package base.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TreadPoolExcutorTest {
	private static ThreadPoolExecutor threadPoolForReportTask = new ThreadPoolExecutor(2, 6, 3, TimeUnit.SECONDS,
			new ArrayBlockingQueue<Runnable>(500), new ThreadPoolExecutor.CallerRunsPolicy());
	static {
		threadPoolForReportTask.allowCoreThreadTimeOut(true);
	}
	public static void main(String[] args) throws InterruptedException {
		Thread.sleep(1000);
		System.out.println("开始线程池");
		System.out.println(threadPoolForReportTask.getActiveCount());
		System.out.println(threadPoolForReportTask.getPoolSize());
		threadPoolForReportTask.execute(new Runnable() {
			@Override
			public void run() {
				System.out.println("线程执行");
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("线程执行完毕");
			}
		});
		Thread.sleep(500);
		System.out.println(threadPoolForReportTask.getActiveCount());
		System.out.println(threadPoolForReportTask.getPoolSize());
		Thread.sleep(2000);
		System.out.println(threadPoolForReportTask.getActiveCount());
		System.out.println(threadPoolForReportTask.getPoolSize());
		Thread.sleep(4000);
		System.out.println(threadPoolForReportTask.getActiveCount());
		System.out.println(threadPoolForReportTask.getPoolSize());
		System.out.println("主线程结束");
	}

}
